package com.ms.education.course.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ms.education.R;
import com.ms.education.course.entity.Comment;
import com.ms.education.course.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程评论 前端控制器
 * </p>
 *
 * @author ms
 * @since 2023-01-17
 */
@RestController
@RequestMapping("/course/comment")
public class CommentController {


    @Autowired
    private CommentService commentService;

    @PutMapping("saveComment")
    public R saveComment(Comment comment) {
        commentService.save(comment);
        return R.ok();
    }

    @GetMapping("pageComment/{current}/{limit}/{courseId}")
    public R pageComment(@PathVariable("current") long current,
                         @PathVariable("limit") long limit,
                         @PathVariable("courseId") Integer courseId) {
        Page<Comment> page = commentService.pageComment(current, limit,courseId);
        return R.ok().data("rows", page.getTotal()).data("comments", page.getRecords());
    }

}
